﻿using System;
using System.Runtime.Serialization;
using Stats;
using Stats.Objects;
using System.Collections.Generic;
using System.Linq;

namespace TripLOA.WebService.Wrappers
{
    /// <summary>
    /// A serializable rapresentation of the Security.Profile class
    /// </summary>
    [DataContract]
    public class ProfileInfo
    {
        /// <summary>
        /// Parameterless Constructor
        /// </summary>
        public ProfileInfo() { }


        /// <summary>
        /// Constructor. Set all fields to the values of the given Profile object
        /// </summary>
        /// <param name="p">A Security.Profile object</param>
        public ProfileInfo(Security.Profile p)
        {
            this.Id = p.Id;
            this.Username = p.Username;
            this.Feedbacks = p.Feedbacks;
            this.Name = p.Name;
            this.Surname = p.Surname;
            this.Address = p.Address;
            this.Age = p.Age;
            this.City = p.City;

            try
            {
                this.DrivingLicense = p.DrivingLicence;
            }
            catch (Exception)
            {
                //FIXME aspettando che venga corretto...
            }

            this.Email = p.Email;
            //Events = p.Events;
            this.PhoneNumber = p.PhoneNumber;
            this.Smoker = p.Smoker;
            this.Birthday = p.Birthday;
            this.Interests = p.Interests;
            this.Gender = p.Gender;

            //this.BannedList = new List<UserInfo>();
            //FIXME aspettando che venga corretto...
            /*if (p.BannedList != null)
            {
                foreach (var banned in p.BannedList)
                {
                    UserInfo user = new UserInfo();
                    user.Username = banned.Username;
                    user.NumericFeedbacks = UserCore.Instance.GetUserNumericFeedback(banned);
                    user.UserID = banned.Id;
                    this.BannedList.Add(user);
                }
            }*/

            //this.BuddyList = new List<UserInfo>();
            //FIXME aspettando che venga corretto...
            /*if (p.BuddyList != null)
            {
                foreach (var buddy in p.BuddyList)
                {
                    UserInfo user = new UserInfo();
                    user.Username = buddy.Username;
                    user.NumericFeedbacks = UserCore.Instance.GetUserNumericFeedback(buddy);
                    user.UserID = buddy.Id;
                    this.BuddyList.Add(user);
                }
            }*/

            //this.VehicleDetails = new List<VehicleInfo>();
            //FIXME aspettando che venga corretto...
            
            /*foreach (Storage.EntityModels.VehicleDetails vehicle in p.VehiclesDetails)
            {
                VehicleInfo ve = new VehicleInfo(vehicle);
                ve.Id = vehicle.Id;
                ve.Model = vehicle.Model;
                ve.VehicleClass = vehicle.VehicleClass;
                ve.MaxSeatNumber = ve.GetMaxSeatsNumberByModel(ve.Model);
                VehicleDetails.Add(ve);
            } */
            
            
        }

        #region Properties

        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string Username { get; set; }
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string Surname { get; set; }
        [DataMember]
        public string Address { get; set; }
        [DataMember]
        public int Age { get; set; }
        [DataMember]
        public string City { get; set; }
        [DataMember]
        public bool? DrivingLicense { get; set; }
        [DataMember]
        public string Email { get; set; }
        
        [Obsolete]
        [DataMember]
        public string Events { get; set; }
        [DataMember]
        public string PhoneNumber { get; set; }
        [DataMember]
        public Storage.EntityModels.Smoker Smoker { get; set; }
        [DataMember]
        public List<Feedback> Feedbacks;
        /*[DataMember]
        public List<UserInfo> BannedList { get; set; }*/
        [DataMember]
        public DateTime? Birthday { get; set; }
        /*[DataMember]
        public List<UserInfo> BuddyList { get; set; }*/
        [DataMember]
        public List<string> Interests {get; set;}
        [DataMember]
        public Storage.EntityModels.Gender Gender { get; set; }
        /*[DataMember]
        public List<VehicleInfo> VehicleDetails { get; set; }*/
    
        #endregion
    }

    #region UserInfo
    /// <summary>
    /// Serializable rapresentation of a Security.TripLoaUser class
    /// </summary>
    [DataContract]
    public class UserInfo
    {
        /// <summary>
        /// Parameterless Constructor
        /// </summary>
        public UserInfo()
            : base() { }

        /// <summary>
        /// Constructor. Set all fields to the values of the given TripLoaUser object
        /// </summary>
        /// <param name="user">Security.TripLoaUser object</param>
        public UserInfo(Security.TripLoaUser user)
        {
            this.UserID = user.UserID;
            this.Username = user.UserName;
            Security.Profile profile = user.GetProfile();
            ProfileInfo profileInfo = new ProfileInfo(profile);
            this.NumericFeedbacks = UserCore.Instance.GetUserNumericFeedback(profile);
        }

        /// <summary>
        /// Constructor. Create an instance of UserInfo given an user profile
        /// </summary>
        /// <param name="profile">The user profile</param>
        public UserInfo(Security.Profile profile)
        {
            this.UserID = profile.Id;
            this.Username = profile.Username;
            this.NumericFeedbacks = UserCore.Instance.GetUserNumericFeedback(profile);
        }

        [DataMember]
        public int UserID { get; set; }
        [DataMember]
        public string Username { get; set; }
        [DataMember]
        public decimal NumericFeedbacks { get; set; }
    }
 
    #endregion
    /// <summary>
    /// Serializable rapresentation of a Storage.EntityModels.VehicleDetails
    /// </summary>
    [DataContract]
    public class VehicleInfo
    {
        public VehicleInfo() { }

        // added by anonimyzer
        public VehicleInfo(Storage.EntityModels.Users_VehicleDetails vehicle)
        {
            this.Id = vehicle.Id;
            this.Model = vehicle.VehicleDetails.Model;
            this.VehicleClass = vehicle.VehicleDetails.VehicleClass;
            this.MaxSeatNumber = this.GetMaxSeatsNumberByModel(this.Model);
        }

        public VehicleInfo(Storage.EntityModels.VehicleDetails vehicle)
        {
            this.Id = vehicle.Id;
            this.Model = vehicle.Model;
            this.VehicleClass = vehicle.VehicleClass;
            this.MaxSeatNumber = this.GetMaxSeatsNumberByModel(this.Model);
        }
        public int GetMaxSeatsNumberByModel(string model)
        {
            int seats = 0;
            switch (model)
            {
                case "Auto berlina":
                    seats = 8;
                    break;
                case "Auto sportiva":
                    seats = 4;
                    break;
                case "SUV":
                    seats = 8;
                    break;
                case "Auto utilitaria":
                    seats = 5;
                    break;
                case "Auto a noleggio":
                    seats = 8;
                    break;
                case "Moto":
                    seats = 1;
                    break;
            }
            return seats;
        }
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string Model { get; set; }
        [DataMember]
        public float? Co2Emission { get; set; }
        [DataMember]
        public float? FuelConsumption { get; set; }
        [DataMember]
        public Storage.EntityModels.VehicleTypes VehicleClass { get; set; }
        [DataMember]
        public int MaxSeatNumber { get; set; }
    }
}
